package com.Service.DAO;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author michaelomar
 */
import java.sql.*;

public class ConnectionManager {

    static Connection con;

    public Connection getCon() {
        if (con == null) {
            try {
                Class.forName("com.mysql.jdbc.Driver");
                con = DriverManager.getConnection("jdbc:mysql://localhost:3306/HR-Service", "root", "");
                Statement st = con.createStatement();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        return con;
    }

    public ResultSet ExecuteQuery(String query) {
        ResultSet rs = null;
        try {
            Statement st = con.createStatement();
            rs = st.executeQuery(query);
        } catch (Exception e) {
        }
        return rs;
    }

    public synchronized void ExecuteNonQuery(String query) {
        try {
            Statement st = con.createStatement();
            st.executeUpdate(query);
        } catch (Exception e) {
        }
    }

    public synchronized void closeDB() {
        try {
            con.close();
        } catch (Exception e) {
        }
    }
}
